package de.pharmacontrol.utils;


public class AiMappingObj implements Comparable<AiMappingObj>{

	private final String ai;
	private final String name;
	private final String descr;
//	private final int sort;
	private int rank = -1;
	private final String type;
	private String format;
	private String value;
	private final boolean fixRank;
	private boolean depends = false;
	private final boolean statics;
	
	private final int minLength;
	private final int maxLength;
	
	public AiMappingObj(String ai, String name, String descr, String type, String format) {
		this(ai, name, descr, type, format, -1, false, false, true);
	}

	public AiMappingObj(String ai, String name, String descr, String type, String format, int rank, boolean isfixrank, boolean depends, boolean statics) {
		this(ai, name, descr, type, format, rank, isfixrank, depends, statics, 0, 255);
	}

	public AiMappingObj(String ai, String name, String descr, String type, String format, int rank, boolean isfixrank, boolean depends, boolean statics, int min, int max) {
		this.ai = ai;
		this.name = name;
		this.descr = descr;
		this.rank = rank;
		this.type = type;
		this.format = format;
		this.fixRank = isfixrank;
		this.setDepends(depends);
		this.statics = statics;
		this.minLength = min;
		this.maxLength = max;
	}
	
	public String getAi() {
		return ai;
	}

	public String getName() {
		return name;
	}

	public String getDescr() {
		return descr;
	}

//	public int getSort() {
//		return sort;
//	}

	public String getType() {
		return type;
	}

	public void setFormat(String format) {
		this.format = format;
	}
	
	public String getFormat() {
		return format;
	}

	@Override
	public String toString() {
		return String.valueOf("(" + ai + ") " + name);
	}

	public void setRank(int rank) {
		if (!fixRank)
			this.rank = rank;
	}

	public int getRank() {
		return rank;
	}
	
	public boolean isFixRank() {
		return fixRank;
	}
	
	public void setValue(String value) {
		this.value = value;
	}

	public String getValue() {
		return value;
	}

	public void setDepends(boolean depends) {
		this.depends = depends;
	}

	public boolean isDepends() {
		return depends;
	}

	public boolean isStatics() {
		return statics;
	}

	public int getMinLength() {
		return minLength;
	}

	public int getMaxLength() {
		return maxLength;
	}

	@Override
	public int hashCode() {
		return ai.hashCode() + rank;
	}
	
	@Override
	public int compareTo(AiMappingObj o) {
		if (getRank() == o.getRank() && getAi().equals(o.getAi()))
			return 0;
		if (rank == o.getRank())
			return getAi().compareTo(o.getAi());

		else
			return ((Integer) getRank()).compareTo((Integer) o.getRank());
	}

}
